<script type="text/javascript">
    $(document).ready(function()
    {
        $('#feedback').dataTable({
            "bStateSave": true,
            "aLengthMenu": [[-1, 5, 10, 25, 50], ["All", 5, 10, 25, 50]],
            "iDisplayLength": -1,
            "aoColumns": [
                {"bSortable": false} ,
                null,
                null,
                null,
                null,
                null,
                null,
                {"bSortable": false} ,
                //                    {"bSortable": false} ,
                //                    {"bSortable": false}
            ]
        });
            
    });
    
    function deleteFeedback(id){
        var r = confirm("Do you confirm to delete this feedback?");
        if(r){
            var success = "admin/deleteFeedback?id=" + id;
            $.get(success)
            .success(function(data) {  
//                alert(data)
                var page = baseurl + 'admin/showFeedbacks';
                $.get(page)
                .success(function(data) {
                    $('div#content').html(data);
                });
            });
        }
        return false;
    }
    
    function deleteSelectedFeedback(){
        var checkboxes = document.getElementsByName('feedback');
        if($("input.checkbox:checked").length == 0){
            alert("No feedback is selected!");
            return false;
        }
            
        var r=confirm("Are you sure to delete selected feedbacks?");
        if (r==true)
        {
            for(var i=0, n=checkboxes.length;i<n;i++) {
                if(checkboxes[i].checked){
                    var id = checkboxes[i].value;
                    var success = "admin/deleteFeedback?id=" + id;
                    $.get(success)
                    .success(function(data) {  
                        var page = baseurl + 'admin/showFeedbacks';
                        $.get(page)
                        .success(function(data) {
                            $('div#content').html(data);
                        });
                    });
                }
            }
        }
        return false;
    }
</script>
</head>
<h4>Feedback</h4>
<hr>
<?php if (isset($data) && count($data)) {
    ?>
    <table id="feedback" class="dataTable" style="font-size: 13px">
        <thead>
        <th><input type='checkbox' onClick="selectAllByName(this, 'feedback')" style=""></th>
        <th>Date</th>
        <th>Name</th>
        <th>Affiliation</th>
        <th>Email</th>
        <th>Category</th>
        <th>Comment</th>
        <th></th>
    </thead>
    <tbody>
        <?php
        foreach ($data as $row) {
            $id = $row['id'];
            echo "<tr>";
            echo "<td>";
            echo "<input type='checkbox' name='feedback' class='checkbox' value='$id'>";
            echo "</td>";
            echo "<td>";
            echo $row['date'];
            echo "</td>";
            echo "<td>";
            echo $row['name'];
            echo "</td>";
            echo "<td>";
            echo $row['affiliation'];
            echo "</td>";
            echo "<td>";
            echo $row['email'];
            echo "</td>";
            echo "<td>";
            echo $row['category'];
            echo "</td>";
            echo "<td><textarea style='width: 100%; background: none; border: none; resize: none' rows='4' resize='none' disabled>";
            echo $row['comment'];
            echo "</textarea></td>";
            echo "<td><a href='javascript:void(0);' onclick='deleteFeedback($id)'>Delete</a></td>";
            echo "</tr>";
        }
        echo '</tbody></table>';
        ?>
    <br>
    <div class="medium warning  btn"><input type="submit" value="Delete" onclick="deleteSelectedFeedback()"/></div>
        <?php
    } else {
        echo "No feedback.";
    }
    ?>
</tbody>

</table>
